<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->

<html>
    <head>
        <meta charset="utf-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
        <meta name="description" content="" />
        <meta name="author" content="" />
        <style>
            body {
                font-family: 'Sans', sans-serif;
                line-height: 30px;
                background:url('assets/img/background7.jpg')no-repeat;
                background-size:cover;
            }
            table{
                text-align: center;
            }


            .parent {
                filter:alpha(Opacity=90);
                -moz-opacity:0.8;
                opacity: 0.8;
                background-color: #000;
                color:#fff;
                position:relative;
                width:1300px;
                left:50%;
                margin-left:-650px;
                border:1px solid #fff;
                text-align: center;

            }
            .score-view{
                filter:alpha(Opacity=90);
                -moz-opacity:0.8;
                opacity: 0.8;
                background-color: #000;
                color:#fff;
                position:relative;
                width:1800px;
                left:50%;
                margin-left:-900px;
                border:1px solid #fff;
                text-align: center;
            }
            .admin{
                position:relative;
                left:50%;
                width:760px;
                margin-left:-380px;

            }
            .judge{
                position:relative;
                left:50%;
                width:900px;
                margin-left:-450px;

            }
            .score{
                position:relative;
                left:50%;
                width:634px;
                margin-left:-317px;

            }
            .question{
                position:relative;
                left:50%;
                width:863px;
                margin-left:-431px;
                height: 500px;
            }
            .btn {
                width: 200px;
                height: 60px;
                font-size: 20px;
            }
            button:hover{
                color: #2945a5;
            }
            .form-text-center{
                text-align: center;
                font-size: 20px;
            }
        </style>
        <!--[if IE]>
            <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
            <![endif]-->
        <title>成绩录入</title>

    </head>
    <body>

        <?PHP
        if(!empty($_GET['email'])){$email_admin_=$_GET['email'];}else{$email_admin_='';}
        if(!empty($_GET['rounds'])){$rounds=$_GET['rounds'];}else{$rounds='';}
        if(!empty($_GET['session'])){$round_session=$_GET['session'];}else{$round_session='';}
        if(!empty($_GET['site_number'])){$site_number=$_GET['site_number'];}else{$site_numbers='';}
        if($rounds==1){
        $session=$round_session;
        }elseif($rounds==2){
        $session=$round_session+4;
        }elseif($rounds==3){
        $session=$round_session+7;
        }

        $chairman='';
        $judge[1]='';
        $judge[2]='';
        $judge[3]='';
        $judge[4]='';
        $judge[5]='';
        $school[1]='';
        $school[2]='';
        $school[3]='';
        $school[4]='';

        /*$sql="select * from school_information_list a inner join rounds_match_list b on a.school_number=b.school_1_number where  b.round='$rounds' and b.site='$site_number';";
        echo $sql;$mysqli = mysqli_init();
        $mysqli->options(MYSQLI_OPT_CONNECT_TIMEOUT, 2); //设置超时时间
        $mysqli->real_connect('127.0.0.1', 'root', 'mysql');
        $sql = "CREATE DATABASE IF NOT EXISTS CUPT DEFAULT CHARSET utf8 COLLATE utf8_general_ci;";
        if ($mysqli->query($sql) == TRUE) {
        //printf("Table CUPT successfully created.\n");
        }
        mysqli_select_db($mysqli,"CUPT");
        $rst=$mysqli->query($sql);*/



        if(!empty($_GET['rounds'])&!empty($_GET['session'])&&!empty($_GET['site_number'])){

        $mysqli = mysqli_init();
        $mysqli->options(MYSQLI_OPT_CONNECT_TIMEOUT, 2); //设置超时时间
        $mysqli->real_connect('127.0.0.1', 'root', 'mysql');
        $sql = "CREATE DATABASE IF NOT EXISTS CUPT DEFAULT CHARSET utf8 COLLATE utf8_general_ci;";
        if ($mysqli->query($sql) == TRUE) {
        //printf("Table CUPT successfully created.\n");
        }
        mysqli_select_db($mysqli,"CUPT");
        for($i=1;$i<=3;$i++){
        $sql="select * from school_information_list a inner join rounds_match_list b on a.school_number=b.school_"."$i"."_number where  b.round='$rounds' and b.site='$site_number' and b.session='$session';";
        //echo $sql;
        $rst=$mysqli->query($sql);
        if($rst->num_rows != 0){
        while ($row = mysqli_fetch_assoc($rst)) {


        $school[$i] = $row['school'];

        $chairman_number=$row['chairman_number'];

        //$chairman_qualifications=$chairman_number[1];
        $sql1="select * from judge where `school_number`='$chairman_number[0]' and `chairman_qualifications`='$chairman_number[1]';";
        $rst1=$mysqli->query($sql1);
        $row1 = mysqli_fetch_assoc($rst1);
        $chairman=$row1['name'];


        for($judge_num=1;$judge_num<=5;$judge_num++){
        $judge_number=$row["judge_"."$judge_num"."_number"];

        //$chairman_qualifications=$judge_number[1];
        $sql1="select * from judge where `school_number`='$judge_number[0]' and `chairman_qualifications`='$judge_number[1]';";
        $rst1=$mysqli->query($sql1);
        $row1 = mysqli_fetch_assoc($rst1);
        $judge[$judge_num]=$row1['name'];
        }


        }
        }
        }
        //mysqli_close($mysqli);
        }
        ?>
        <div id="grand" style="margin-top:0px">
            <div id="score_input_div" class="parent">
                <form action="score-input.php" name="score_input" method="post" >
                    <div class="admin">
                        <table border="1">
                            <tr><th>管理员邮箱</th><th>管理员密码</th><th>轮次</th><th>场次</th><th>场地号</th></tr>
                            <tr>
                                <td><input type='text' class='form-control' required='required' id='email' name='email' placeholder='email' value='<?PHP echo "$email_admin_";?>' /></td>
                                <td><input type='password' class='form-control' required='required' id='email' name='password' placeholder='管理员密码' /></td>
                                <td> <input type='number' class='form-control' required='required' id='rounds' name='rounds' oninput='if(value>4)value=4;if(value<1)value=1' placeholder='第几场' readonly='readonly' value='<?PHP echo "$rounds";?>'/></td>
                                <td><input type='number' class='form-control' required='required' id='session' name='session' oninput='if(value>3)value=3;if(value<1)value=1' placeholder='第几轮' readonly='readonly' value='<?PHP echo "$round_session";?>'/></td>
                                <td><input type='number' class='form-control' required='required' id='site_number' name='site_number' oninput='if(value>3)value=3;if(value<1)value=1' placeholder='场地号' readonly='readonly' value='<?PHP echo "$site_number";?>'/></td>     

                            </tr>
                        </table>
                    </div>
                    <div class="judge">
                        <table border="1">
                            <tr><th>主席姓名</th><th>评委1姓名</th><th>评委2姓名</th><th>评委3姓名</th><th>评委4姓名</th><th>评委5姓名</th></tr>
                            <tr>
                                <td><input type="text" class="form-control" required="required" id="chairman_name" name="chairman_name" placeholder="主席姓名" value='<?PHP echo "$chairman";?>'/></td>
                                <td><input type="text" class="form-control" required="required" id="judge_1_name" name="judge_1_name" placeholder="评委1姓名" value='<?PHP echo "$judge[1]";?>'/></td>
                                <td><input type="text" class="form-control" required="required" id="judge_2_name" name="judge_2_name" placeholder="评委2姓名" value='<?PHP echo "$judge[2]";?>'/></td>
                                <td><input type="text" class="form-control" required="required" id="judge_3_name" name="judge_3_name" placeholder="评委3姓名" value='<?PHP echo "$judge[3]";?>'/></td>
                                <td><input type="text" class="form-control" required="required" id="judge_4_name" name="judge_4_name" placeholder="评委4姓名" value='<?PHP echo "$judge[4]";?>'/></td>
                                <td><input type="text" class="form-control" required="required" id="judge_5_name" name="judge_5_name" placeholder="评委5姓名" value='<?PHP echo "$judge[5]";?>'/></td>
                            </tr>
                        </table>
                    </div>



                    <hr />

                    <div class="score">
                        <table border="1">
                            <tr>
                                <th></th>
                                <th>正方</th>
                                <th>反方</th>
                                <th>评论方</th>
                            </tr>
                            <tr>
                                <td style="font-size: 17px">
                                    选手姓名<br />
                                    选手学校<br />
                                    评委1打分<br />
                                    评委2打分<br />
                                    评委3打分<br />
                                    评委4打分<br />
                                    评委5打分<br />
                                </td>
                                <td>
                                    <div><input type="text" class="form-control" required="required" id="name_1" name="name_1" placeholder="正方选手姓名" /></div>
                                    <div><input type="text" class="form-control" required="required" id="school_1"  name="school_1" list="school_list" placeholder="正方选手学校" value='<?PHP echo "$school[1]";?>'/></div>
                                    <datalist id="school_list" >
                                        <?PHP
                                        $school_arr=['哈尔滨工业大学（深圳）','华南理工大学','华中科技大学','华中师范大学','暨南大学','南方科技大学','武汉大学','湘潭大学','中南大学','中山大学'];
                                        for($i=0;$i<=9;$i++){
                                        echo "<option value='$school_arr[$i]'>$school_arr[$i]</option>";
                                        }
                                        ?>
                                    </datalist>
                                    <div><input type="number" class="form-control" required="required" id="judge_1_score_1" name="judge_1_score_1" oninput='if(value>10)value=10;if(value<0)value=0' placeholder="评委1给正方打分" /></div>
                                    <div><input type="number" class="form-control" required="required" id="judge_2_score_1" name="judge_2_score_1" oninput='if(value>10)value=10;if(value<0)value=0' placeholder="评委2给正方打分" /></div>
                                    <div><input type="number" class="form-control" required="required" id="judge_3_score_1" name="judge_3_score_1" oninput='if(value>10)value=10;if(value<0)value=0' placeholder="评委3给正方打分" /></div>
                                    <div><input type="number" class="form-control" required="required" id="judge_4_score_1" name="judge_4_score_1" oninput='if(value>10)value=10;if(value<0)value=0' placeholder="评委4给正方打分" /></div>
                                    <div><input type="number" class="form-control" required="required" id="judge_5_score_1" name="judge_5_score_1" oninput='if(value>10)value=10;if(value<0)value=0' placeholder="评委5给正方打分" /></div>
                                </td>

                                <td>
                                    <input type="text" class="form-control" required="required" id="name_2" name="name_2" placeholder="反方选手姓名" /><br />
                                    <div><input type="text" class="form-control" required="required" id="school_2"  name="school_2" list="school_list" placeholder="反方选手学校" value='<?PHP echo "$school[2]";?>'/></div>
                                    <input type="number" class="form-control" required="required" id="judge_1_score_2" name="judge_1_score_2" oninput='if(value>10)value=10;if(value<0)value=0' placeholder="评委1给反方打分" /><br />
                                    <input type="number" class="form-control" required="required" id="judge_2_score_2" name="judge_2_score_2" oninput='if(value>10)value=10;if(value<0)value=0' placeholder="评委2给反方打分" /><br />
                                    <input type="number" class="form-control" required="required" id="judge_3_score_2" name="judge_3_score_2" oninput='if(value>10)value=10;if(value<0)value=0' placeholder="评委3给反方打分" /><br />
                                    <input type="number" class="form-control" required="required" id="judge_4_score_2" name="judge_4_score_2" oninput='if(value>10)value=10;if(value<0)value=0' placeholder="评委4给反方打分" /><br />
                                    <input type="number" class="form-control" required="required" id="judge_5_score_2" name="judge_5_score_2" oninput='if(value>10)value=10;if(value<0)value=0' placeholder="评委5给反方打分" /><br />
                                </td>

                                <td>
                                    <input type="text" class="form-control" required="required" id="name_3" name="name_3" placeholder="评论方选手姓名" /><br />
                                    <div><input type="text" class="form-control" required="required" id="school_3"  name="school_3" list="school_list" placeholder="评论方选手学校" value='<?PHP echo "$school[3]";?>'/></div>
                                    <input type="number" class="form-control" required="required" id="judge_1_score_3" name="judge_1_score_3" oninput='if(value>10)value=10;if(value<0)value=0' placeholder="评委1给评论方打分" /><br />
                                    <input type="number" class="form-control" required="required" id="judge_2_score_3" name="judge_2_score_3" oninput='if(value>10)value=10;if(value<0)value=0' placeholder="评委2给评论方打分" /><br />
                                    <input type="number" class="form-control" required="required" id="judge_3_score_3" name="judge_3_score_3" oninput='if(value>10)value=10;if(value<0)value=0' placeholder="评委3给评论方打分" /><br />
                                    <input type="number" class="form-control" required="required" id="judge_4_score_3" name="judge_4_score_3" oninput='if(value>10)value=10;if(value<0)value=0' placeholder="评委4给评论方打分" /><br />
                                    <input type="number" class="form-control" required="required" id="judge_5_score_3" name="judge_5_score_3" oninput='if(value>10)value=10;if(value<0)value=0' placeholder="评委5给评论方打分" /><br />
                                </td>
                            </tr>  

                        </table>
                    </div>
                    <hr />
                    <div class="question">
                        <div>
                            <table border="1">
                                <?PHP 
                                $question_state=[2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2];//初始化选题情况
                                $question_arr=array
                                (
                                array(1,12),
                                array(2,4,6,10,16),
                                array(3,5,7,8),
                                array(9,13),
                                array(11,14,15,17)
                                );
                                $question_number_refuse_arr=array
                                (
                                array(2,1),
                                array(5,2),
                                array(4,1),
                                array(2,1),
                                array(4,1)
                                );
                                $self_choose_session_site=array//正方自选题目的场次和场地号
                                (
                                array(3,2),
                                array(4,1),
                                array(5,3),
                                array(6,2),
                                array(7,1),
                                array(8,3),
                                array(9,2),
                                array(10,1),
                                array(10,2),
                                array(10,3),
                                );
                                $self_choose_flag=0;
                                if(in_array([$session,$site_number],$self_choose_session_site)){
                                $self_choose_flag=1;
                                }

                                $class_already_refused=[0,0,0,0,0];//初始化每类别的拒题数量
                                $question=['','','','','','','','','','','','','','','','','',''];
                                //正方
                                $sql="select * from school_question_list where school='$school[1]';";
                                $rst=$mysqli->query($sql);
                                while ($row = mysqli_fetch_assoc($rst)) {
                                for($i=1;$i<=17;$i++){
                                $question[$i]= $question[$i].$row["question_$i"];
                                }
                                }
                                //反方
                                $sql="select * from school_question_list where school='$school[2]';";
                                $rst=$mysqli->query($sql);
                                while ($row = mysqli_fetch_assoc($rst)) {
                                for($i=1;$i<=17;$i++){
                                $question[$i]= $question[$i].$row["question_$i"];

                                if($self_choose_flag==0){//如果自选标志为0，则本场由反方挑战
                                if(strstr($question[$i],'3')){$question_state[$i]=3;}
                                elseif(strstr($question[$i],'4')){$question_state[$i]=4;}
                                elseif(strstr($question[$i],'5')){$question_state[$i]=5;}
                                elseif(strstr($question[$i],'6')){$question_state[$i]=6;}
                                }
                                elseif($self_choose_flag==1){//如果自选标志为1，则本场正方自选
                                if(strstr($question[$i],'4')){$question_state[$i]=4;}
                                }
                                }
                                }
                                $question_class_name=['电磁学','流体力学','声学','光学','固体力学'];
                                $qustion_state_text=['拒绝此题','选则此题','可挑战','不可挑战(A)','不可挑战(B)','不可挑战(C)','不可挑战(D)','不可挑战(E)'];


                                for($i=0;$i<=4;$i++)
                                {
                                $j_limited=$question_number_refuse_arr[$i][0];
                                for($j=0;$j<=$j_limited-1;$j++)
                                {
                                if($question_state[$question_arr[$i][$j]]==3){
                                $class_already_refused[$i]++;
                                //echo $class_already_refused[$i].",$i$j<br/>";
                                }

                                }
                                }



                                for($i=0,$string1="";$i<=4;$i++)
                                {
                                $string1=$string1."<tr>";
                                $j_limited=$question_number_refuse_arr[$i][0];
                                $string1=$string1."<th rowspan='2'>$question_class_name[$i]</th>";
                                $refused_limited[$i]=$question_number_refuse_arr[$i][1]-$class_already_refused[$i];
                                if($refused_limited[$i]<0){$refused_limited[$i]=0;}//如果可拒绝题目数量小于0，则输出0

                                $string1=$string1."<th rowspan='2'><input type='number' class='form-text-center' readonly='readonly' required='required' id='refused_limited_$i' name='refused_limited_$i' value='$refused_limited[$i]'/></th>";

                                for($j=0;$j<=$j_limited-1;$j++)
                                {
                                $qustion_number_string_temp=(string)$question_arr[$i][$j];
                                $string1=$string1."<th>$qustion_number_string_temp</th>";
                                }
                                $string1=$string1."</tr>";


                                $string1=$string1."<tr>";
                                $j_limited=$question_number_refuse_arr[$i][0];
                                for($j=0;$j<=$j_limited-1;$j++)
                                {
                                $qustion_state_temp=$question_state[$question_arr[$i][$j]];
                                $qustion_number_temp=$question_arr[$i][$j];

                                for($k=0,$sub_string1='';$k<=2;$k++)
                                {
                                if($k==$qustion_state_temp)
                                {
                                $sub_string1=$sub_string1."<option value='$k' selected='selected'>$qustion_state_text[$k]";
                                $tmp_k=$k;
                                }
                                else
                                {
                                $sub_string1=$sub_string1."<option value='$k'>$qustion_state_text[$k]";
                                }
                                }
                                for($k=3;$k<=7;$k++)
                                {
                                if($k==$qustion_state_temp)
                                {
                                $sub_string1=$sub_string1."<option value='$k' selected='selected' disabled='true'>$qustion_state_text[$k]";
                                $tmp_k=$k;
                                }
                                else
                                {
                                $sub_string1=$sub_string1."<option value='$k' disabled='true'>$qustion_state_text[$k]";
                                }
                                }

                                if($tmp_k>=3){
                                $sub_string1="<select required='required' id='question_$qustion_number_temp' name='question_$qustion_number_temp' onfocus='this.defOpt=this.selectedIndex' onchange='this.selectedIndex=this.defOpt;'>".$sub_string1;
                                }else{
                                $sub_string1="<select required='required' id='question_$qustion_number_temp' name='question_$qustion_number_temp' onchange='select_limit()'>".$sub_string1;
                                }
                                $string1=$string1."<td>$sub_string1</td>";
                                }
                                $string1=$string1."</tr>";

                                }
                                if($self_choose_flag==0){
                                echo "<tr><th colspan='7'>正方可被挑战题目</th></tr>";
                                }else{
                                echo "<tr><th colspan='7'>正方可被挑战题目(本场正方自选)</th></tr>";
                                }
                                echo "<tr><th>题目类别</th><th>此类别剩余可拒绝数量</th><th colspan='5'>题目编号</th></tr>";
                                echo $string1; 

                                ?>
                            </table>
                        </div>
                        <div class="form-group">
                            <button id="score_input" type="submit" class="btn" onclick="score_input_button()">点击提交比赛分数</button>
                        </div>
                    </div>
                </form>
            </div> 
        </div>

        <script type='text/javascript'>
            window.onload = function () {
                select_limit();
            }
            function score_input_button() {
                document.getElementById("session").value = "<?PHP echo $session;?>";
                document.score_input.action = "score-input.php";
                document.score_input.submit();
                document.getElementById("session").value = "<?PHP echo $round_session;?>";
            }
            function select_limit()
            {
                qustion_state = ['-1', '2', '2', '2', '2', '2', '2', '2', '2', '2', '2', '2', '2', '2', '2', '2', '2', '2', '2'];
                qustion_refused = [-1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
                flag = 0;
                for (qustion = 1; qustion <= 17; qustion++) {
                    qustion_state[qustion] = document.getElementById("question_" + qustion).value;
                    if (qustion_state[qustion] == 0)
                    {
                        qustion_refused[qustion] = 1;
                    }
                    if (qustion_state[qustion] == 1)
                    {
                        flag++;
                    }
                    if (flag >= 2)
                    {
                        document.getElementById("score_input").disabled = true;
                    } else {
                        document.getElementById("score_input").disabled = false;
                    }
                }


                question_arr =
                        [
                            [1, 12],
                            [2, 4, 6, 10, 16],
                            [3, 5, 7, 8],
                            [9, 13],
                            [11, 14, 15, 17]
                        ];
                question_number_refuse_arr =
                        [
                            [2, "<?PHP echo $refused_limited[0] ?>"],
                            [5, "<?PHP echo $refused_limited[1] ?>"],
                            [4, "<?PHP echo $refused_limited[2] ?>"],
                            [2, "<?PHP echo $refused_limited[3] ?>"],
                            [4, "<?PHP echo $refused_limited[4] ?>"]
                        ];


                for (i = 0; i <= 4; i++) {
                    for (j = 0, sum_refused = 0; j <= question_number_refuse_arr[i][0] - 1; j++) {
                        sum_refused = sum_refused + qustion_refused[question_arr[i][j]];
                    }
                    if (question_number_refuse_arr[i][1] - sum_refused >= 0) {
                        document.getElementById("refused_limited_" + i).value = question_number_refuse_arr[i][1] - sum_refused;
                        document.getElementById("refused_limited_" + i).style.color = '#000';
                    } else {
                        document.getElementById("refused_limited_" + i).value = question_number_refuse_arr[i][1] - sum_refused;
                        document.getElementById("refused_limited_" + i).style.color = 'red';//"<font color='red'>0</font>";
                    }
                }

            }







        </script>





    </body>
</html>
